<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改用户身份</title>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" disabled name="name" th:value="${user.name}" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>电话
            </label>
            <div class="layui-input-inline">
                <input type="text" id="tel" disabled name="tel" th:value="${user.tel}" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>当前身份
            </label>
            <div class="layui-input-inline">
                <input type="text" id="oldIdentity" disabled name="oldIdentity" th:value="${user.identity}" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>新身份
            </label>
            <div class="layui-input-inline">
                <select id="newIdentity" name="newIdentity" style="width: 150px; height: 37px" lay-verify="newIdentity">
                    <option value="请选择">请选择</option>
                    <option value="buyer">buyer</option>
                    <option value="sys_admin">sys_admin</option>
                    <option value="war_admin">war_admin</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="change" lay-submit="">
                修改
            </button>
        </div>
        <span id="info" style="color: red"></span>
    </form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            newIdentity: function(value){
                if(value=="请选择"){
                    return '请选择新身份';
                }
                if(value==document.getElementById("oldIdentity").value){
                    return '新身份不能与旧身份相同';
                }
            }
        });

        //修改
        form.on('submit(change)', function(data){

            //获取手机号、新身份
            var tel = document.getElementById("tel").value;
            var identity = document.getElementById("newIdentity").value;
            $.ajax({
                url:"/userAdmin/editIdentity",
                type:"post",
                data:{"tel":tel, "identity":identity},
                dataType:"json", //返回的数据类型
                success:function (data) {
                    $("#info").text(data.info);
                    if(data.info == "修改成功"){
                        //关闭弹窗，获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        //刷新
                        parent.window.location.href = parent.window.location.href;
                    }
                }
            })
            return false;
        });


    });
</script>
<script>
    var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
    })();
</script>
</body>

</html>